package com.quanshu.change.person.view;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.gyf.barlibrary.ImmersionBar;
import com.quanshu.change.person.adapter.NjfListAdapter;
import com.quanshu.change.person.entity.NjfListEntity;
import com.quanshu.exchange.R;
import com.quanshu.exchange.support.api.ShopInterface;
import com.quanshu.exchange.support.net.BaseResponse;
import com.quanshu.exchange.support.net.core.BaseObserver;
import com.quanshu.exchange.support.net.core.BaseTransformer;
import com.quanshu.exchange.support.net.core.NetClient;
import com.quanshu.exchange.support.utils.AppUtils;
import com.quanshu.exchange.support.utils.LogUtil;
import com.quanshu.exchange.support.utils.ToastHelper;
import com.quanshu.exchange.ui.base.BaseActivity;
import com.quanshu.shop.base.view.BaseTitleBar;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class NjfListActivity extends BaseActivity {

    @BindView(R.id.title_bar)
    BaseTitleBar titleBar;
    @BindView(R.id.rl)
    RecyclerView rl;
    private NjfListAdapter njfListAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_njf_list);
        ButterKnife.bind(this);
        initView();
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        ImmersionBar.with(this).destroy();
    }
    private void initView() {
        ImmersionBar.with(this).titleBar(titleBar).statusBarColor(R.color.white).statusBarDarkFont(true).init();
        titleBar.setLeftImage(R.drawable.icon_back_black_2_0).setCenterText("牛积分交易记录").setOnClickBaseTitleListener(new BaseTitleBar.OnClickBaseTitleBarListener() {
            @Override
            public void onclickLeft() {
                finish();
            }

            @Override
            public void onclickRight() {

            }
        });
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        rl.setLayoutManager(linearLayoutManager);
        getTransRecord();
    }

    private void getTransRecord() {
        NetClient.getInstance()
                .getShopService(ShopInterface.class)
                .getNjfList(AppUtils.getSignParams(String.valueOf(currentUser.getId())),
                        String.valueOf(currentUser.getId()), "1")
                .compose(new BaseTransformer<>(this))
                .subscribe(new BaseObserver<BaseResponse<List<NjfListEntity>>>() {
                    @Override
                    public void onSuccess(BaseResponse<List<NjfListEntity>> response) {
                        if (response.getData() != null && response.getData().size() > 0) {
                            njfListAdapter = new NjfListAdapter(response.getData());
                            rl.setAdapter(njfListAdapter);
                        } else {
                            ToastHelper.toast("暂无牛积分交易记录");
                        }
                    }

                    @Override
                    public void onFailure(Throwable e) {
                        LogUtil.printException(e);
                    }
                });
    }
}
